package com.youlu.myapplication.scratch;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

public class dfo {
    private static Gson a;

    public static String a(Object obj) {
        return obj == null ? "" : a().toJson(obj);
    }

    public static <T> T a(String str, Type type) {
        return b().fromJson(str, type);
    }

    public static <T> T a(String str, Class<T> cls) {
        return b().fromJson(str, cls);
    }

    public static Gson a() {
        return c();
    }

    public static Gson b() {
        return c();
    }

    private static synchronized Gson c() {
        Gson gson;
        synchronized (dfo.class) {
            if (a == null) {
                a = new GsonBuilder().registerTypeAdapter(Double.class, new JsonSerializer<Double>() {
                    /* renamed from: a */
                    @Override
                    public JsonElement serialize(Double d, Type type, JsonSerializationContext jsonSerializationContext) {
                        if (d.doubleValue() == ((double) d.longValue())) {
                            return new JsonPrimitive((Number) Long.valueOf(d.longValue()));
                        }
                        return new JsonPrimitive((Number) d);
                    }
                }).create();
            }
            gson = a;
        }
        return gson;
    }
}